﻿using System;
using System.Collections;

public class PlayerPhase 
{ 
	private JoyUtil util = new JoyUtil(); // for time, random

	public enum Phase {input, change, attack, waitToTurn};

	public Phase playerPhase;
	public Phase enemyPhase;
	public double partyTimer;
	public float partySpeed;
	public static int partyCount = 4;

    Player[] party = new Player[partyCount];

	//string[] party = {"p1","p2","p3","p4"};
	//string[] tempParty = new string[4];
	public int tempPartyPosision;

	// Use this for initialization
	public void Start () 
	{
		playerPhase = Phase.waitToTurn;
		partyTimer = 0f;
		partySpeed = 3f;
//		partyCount = party.Length;


		for (int i = 0 ; i < partyCount ; i++)
		{
			party[i] = new Player();
//			party[i].currentPosition = i;
		}

	}
	
	// Update is called once per frame
	public void Update () 
	{
		switch (playerPhase)
		{
		case Phase.input:
			//Debug.Log ("input phase");
			//일단 UI에서 받아오는건 못하니까, 임의로 밀당
			int chosenPosition = util.RandomRange(0,partyCount);
			string chosen = party[chosenPosition].Name;
            Console.WriteLine("Chosen = "+chosen+" and position is "+chosenPosition);

//			tempParty[0] = chosen;
			int chosenPassed = 0;

			for (int i = 0; i <= partyCount-1 ; i++)
			{
				if (i == chosenPosition)
					chosenPassed = 1;
				else
				{
					tempPartyPosision = i - chosenPassed + 1;
					Console.WriteLine("Put Party "+i+" to "+tempPartyPosision);
//					tempParty[tempPartyPosision] = party[i];
				}
			}

			playerPhase = Phase.change;
			break;

		case Phase.change:
//			Debug.Log ("change phase");
//			party = tempParty;

			foreach (Player member in party) 
			{
				Console.WriteLine(member);
			}
			playerPhase = Phase.attack;
			break;

		case Phase.attack:
//			Debug.Log ("attack phase");
			playerPhase = Phase.waitToTurn;
			break;

		case Phase.waitToTurn:
			//partyTimer += Time.deltaTime;
            partyTimer += util.DeltaTime();

			if (partyTimer >= partySpeed)
			{
				playerPhase = Phase.input;
				partyTimer = 0f;
			}
			break;
		}
	}
}